package cn.com.dycc.party_work.education_result_dept.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.party_work.education_result_dept.entity.EducationResultDept;
import cn.com.dycc.party_work.education_result_dept.entity.EducationResultDeptInfo;
import cn.com.dycc.party_work.education_result_dept.param.EducationResultDeptParam;
import cn.com.dycc.party_work.education_result_dept.service.EduResultDeptNotFoundException;
import cn.com.dycc.party_work.education_result_dept.service.EducationResultDeptService;
import cn.com.dycc.util.JsonObjectResult;
/**
 * 
 * Description: 
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年7月4日 上午9:30:54.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/education/result/dept")
public class EducationResultDeptController extends BaseController{
	@Resource
	private EducationResultDeptService eduService;

	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addEduResultDept(EducationResultDept eduResult,HttpServletRequest req) throws EduResultDeptNotFoundException, UnsupportedEncodingException{
		int n = eduService.addEduResultDept(eduResult, req);
		return new JsonObjectResult(n);
	}
	
	
	@RequestMapping("/findone.do")
	@ResponseBody
	public JsonObjectResult findEduResultDept(String result_id,HttpServletRequest req){
		EducationResultDept edu = eduService.findEduResultDept(result_id, req);
		return new JsonObjectResult(edu);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findEduResultDeptByParam(EducationResultDeptParam param,HttpServletRequest req){
		String count = eduService.findEduResultDeptCount(param, req);
		List<EducationResultDeptInfo> list = eduService.findEduResultDeptByParam(param, req);
		return new JsonObjectResult(count,list);
	}	
	
	@RequestMapping("/findd.do")
	@ResponseBody
	public JsonObjectResult findEduResultDetpD(EducationResultDeptParam param,HttpServletRequest req){
		HttpSession session = req.getSession();
		String dept_id = (String) session.getAttribute("dept_id");
		param.setDept_id(dept_id);
		String count = eduService.findEduResultDeptCount(param, req);
		List<EducationResultDeptInfo> list = eduService.findEduResultDeptByParam(param, req);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteEduResultDetp(String result_ids[],HttpServletRequest req){
		int n = eduService.deleteEduResultDept(result_ids, req);
		return new JsonObjectResult(n);
	}
	
	@ExceptionHandler(EduResultDeptNotFoundException.class)
	@ResponseBody
	public JsonObjectResult eduException(EduResultDeptNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(99,e);
	}
}
